package com.demo.service;

import com.demo.Dao.Jdbc;
import com.demo.moudel.User;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 * com.demo.service
 * 26832
 * demo-servlet
 * &#064;description: 实现UserService
 * &#064;author: lxm
 * UserServiceImple
 * &#064;create: 2024-04-15 21:42
 **/

public class UserServiceImple implements UserService{
    @Override
    public boolean UserLogin(User user) throws SQLException {
        Jdbc jdbc = new Jdbc();
        User user1 = new User();
        Connection con = jdbc.getConnection();
        String sql = "select * from users where username = '"+user.getName()+"' and password ='"+user.getPassword()+"'";
        Statement stmt = con.createStatement();
        List<User> list = new ArrayList<>();
        ResultSet rs = stmt.executeQuery(sql);
        while(rs.next()){
            user1.setName(rs.getString("username"));
            user1.setPassword(rs.getString("password"));
            list.add(user1);
        }
        jdbc.close(con,stmt,rs);
        return !list.isEmpty();
    }
}
